package jpave.qr;

import jpave.dataholders.GlobalSettings;
import util.Debug.ErrorReport;

public class QRMain {

	public static void main(String[] args) {
		 GlobalSettings settings = loadSettings();
		 try {
			 
			 if (args.length == 0) 
				 new QRFrame(settings);
			 else { // used by viewSingleTCW
				String db = args[args.length-1];
				String[] tokens = db.split(":");	
				if ( tokens.length != 3) ErrorReport.die("Usage: runDE host:database:id");
				new QRFrame(settings, db);
			 }
		}
		catch(java.lang.UnsatisfiedLinkError e)
		{
			System.out.println("\n\n***Probably you need to put libjri.so into one of these directories:***\n");
			System.out.println(System.getProperty("java.library.path") );
			e.printStackTrace();
		}
		catch(Exception e)
		{
			System.out.println("Fatal error in runDE");
			e.printStackTrace();
		}
	}

    static GlobalSettings loadSettings ()
    {
        try
        {
            // Load in the assemblies from the configuration file
        		GlobalSettings settings = new GlobalSettings ();
        		settings.loadFromHosts( ); 
            return settings;
        }
        catch ( Exception err )
        {
        	err.printStackTrace();
            ErrorReport.reportError(err, "reading HOSTS.cfg");
            return null;
       }
    }
}
